﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using INSTA.Library;
using INSTA.BankApplication.DAL;

namespace INSTA.BankApplication.ConsoleUI
{
    class Program
    {
        static void Main(string[] args)
        {
            //Test_Save_ForInsert();
            //Test_Load();
            Test_Save_ForUpdate();
        }

        private static void Test_Load()
        {
            var p = new Person(2);

            ObjectDumper.Write(p);

        }



        private static void Test_Save_ForInsert()
        {
            var p = new Person();

            p.Name          = "toto";
            p.FirstName     = "titi";
            p.YearOfBirth   = 1955;

            p.Save();
        }

        private static void Test_Save_ForUpdate()
        {
            var p = new Person(2);

            p.Name = "AA";
            p.FirstName = "BB";
            p.YearOfBirth = 2013;

            p.Save();

            var p2 = new Person(2);
            ObjectDumper.Write(p2,1);

        }




     



        private static void Test_DAL_Objects()
        {
                       var p = new Person();

            p.Name          = "toto";
            p.FirstName     = "titi";
            p.YearOfBirth   = 1955;

            // On parcourt le dictionnaire d'objet MappedProperty
            // qui a été créé à l'instanciation..
            foreach (var mappedProp in p.MappedProperties.Values)
            {
                Console.WriteLine("Property Name : {0}", mappedProp.PropertyName);
                Console.WriteLine("Field Name    : {0}", mappedProp.FieldName);
                Console.WriteLine("IsPrimaryKey  : {0}", mappedProp.IsPrimaryKey);
                Console.WriteLine("PropertyValue : {0}", mappedProp.PropertyValue);
                Console.WriteLine();
            }

            Console.WriteLine("Table Name : {0}", p.DbAccessor.SqlGenerator.GetTableName()  );

            Console.WriteLine("PrimaryKey Property Name : {0}", p.DbAccessor.SqlGenerator.GetPrimaryKeyPropertyName());

            Console.WriteLine();
            Console.WriteLine(p.DbAccessor.SqlGenerator.GenerateSQLFor_Select());


            Console.WriteLine();
            Console.WriteLine(p.DbAccessor.SqlGenerator.GenerateSQLFor_Delete());

            Console.WriteLine();
            Console.WriteLine(p.DbAccessor.SqlGenerator.GenerateSQLFor_Insert());



            Console.WriteLine();
            Console.WriteLine(p.DbAccessor.SqlGenerator.GenerateSQLFor_Update());

            Console.WriteLine();

        }



    }


}
